import tokenStore from "../utils/tokenStore";
import userStore from "../utils/userStore";

export const getUserInfo = async () => {
	
	return await new Promise(function(resolve, reject) {
		
		uni.request({
			// method: 'POST',
			url: 'https://zm.quya.vip/api/v1/me',
			header: {
				'Authorization': 'Bearer ' + tokenStore.get()
			},
			withCredentials:true,
			sslVerify: false, 
			success: (res) => {
				console.log(res)
				if (res.data.code == 200) {
					let userInfo = res.data.data;
					userInfo.logo ='https://zm.quya.vip/storage/'+ userInfo.logo
					userStore.set(res.data.data);
					
					console.log(userStore.get());
					
					resolve(res.data.data)
				} else {
					uni.showToast({
						title: res.data.message || res.data.msg,
						icon: 'none'
					})
					reject(res.data)
				}
			}
		});
	});
	
}